﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
   public class BachocDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Bachoc");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }
        public bool Delete(string id)
        {
            var sql = "sp_Delete_Bachoc {0}";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Bachoc)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Bachoc '{0}', N'{1}', {2}";
            sql = string.Format(sql, o.MABAC, o.TENBAC, o.HESO);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Bachoc)obj;
            var sql = "set dateformat dmy; execute sp_Update_Bachoc '{0}', N'{1}', {2} ";
            sql = string.Format(sql, o.MABAC, o.TENBAC, o.HESO);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Bachoc";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        //public DataTable Search_MaNhanvien(string name)
        //{
        //    //var sql = @"set dateformat dmy; execute sp_Search_MaNhanvien '" + name + "' ";
        //    //sql = string.Format(sql, name);
        //    //return ExecuteQuery(sql);
        //}

        //public DataTable Search_TenNhanvien(string name)
        //{
        //    //var sql = @"Select MANHANVIEN, HOTEN,(Case when GIOITINH=1 then 'Nam' else N'Nữ' end) as GIOITINH, NGAYSINH, SCMND, DANTOC, TONGIAO, QUEQUAN, CHOOHIENNAY, TRINHDOHOCVAN, DIENTHOAI, EMAIL, NGAYTHAMGIACONGTAC, NGAYNGHICONGTAC, NGAYAPDUNG, MABAC, MAPHONGBAN from tb_Nhanvien Where HOTEN like N'%" + name + "%'  ";
        //    //sql = string.Format(sql, name);
        //    //return ExecuteQuery(sql);
        //}

        public DataTable Search(DAL.Entities.Bachoc o)
        {
            string sql;
            if (o.MABAC != "")
                sql = @"Select * from tb_Bachoc Where MABAC like '%" + o.MABAC + "%'  ";
            else
                sql = @"Select * from tb_Bachoc Where TENBAC like N'" + o.TENBAC + "' or HESO like N'" + o.HESO + "'";

            return ExecuteQuery(sql);
        }
    }
}
